/*
 * JniRecordCaster.h
 *
 *  Created on: 2018年9月2日
 *      Author: zhengboyuan
 */

#ifndef JNI_JNIRECORDCASTER_H_
#define JNI_JNIRECORDCASTER_H_

#include "PsRecordCaster.h"
#include "TCriticalSection.h"
#include <jni.h>


class JniRecordCaster : public av::PsRecordCasterSink
{
public:
	static JniRecordCaster& instance();

	static void init();
	static void quit();

public:
	JniRecordCaster();
	virtual ~JniRecordCaster();

	bool open(const char* dbpath);

	void close();

	bool isOpen();

	av::PsRecordCaster& getCaster();


	void setJvm(JavaVM* jvm);

	void setListener(JNIEnv * env, jobject jlistener);

	void releaseListener(JNIEnv * env);


protected:
	virtual void onCasterEvent(int channel, int event);


protected:
	void fireCasterEvent(int channel, int event);

protected:
	comn::CriticalSection	m_cs;

	JavaVM*	m_jvm;
	jobject	m_listener;

};

#endif /* JNI_JNIRECORDCASTER_H_ */
